package
{
	import com.greensock.TweenLite;

	import fl.transitions.Tween;
	import fl.transitions.easing.Elastic;
	import fl.transitions.easing.Strong;

	import flash.display.Sprite;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;

	import utils.Button;
	import utils.Debuger;
	import utils.UIHelper;

	[SWF(backgroundColor="0x555555", width="655", height="442")]
	/**
	 * 游戏桌，菜单及显示
	 * @author long
	 */
	public class Main extends Sprite
	{
		private var desktable:DeskTable;
		private var btn_GameWord:Button;
		private var mainMenuArray:Array=[];
		public var currentMainMenuName:String;
		public var curentContent:MainMenuItem;
		private var mainMenuMask:Sprite=new Sprite();
		private var mainMenuContainer:Sprite=new Sprite();
		private var boolShowMenu:Boolean;
		private var mainMenuStartX:int=0;
		private var mainMenuStartY:int=107;
		private var mainMenuWidth:int=148;
		private var mainMenuHeight:int=319;
		private var boolTweenLite:Boolean=false;
		private var myTween:Tween;

		public function Main()
		{
			super();
			initSprite();
		}

		private function initSprite():void
		{
			// TODO Auto Generated method stub
			Debuger.init(stage);
			Debuger.print("app has start" + new Date());
			Debuger.print("hello");
			this.stage.scaleMode=StageScaleMode.NO_SCALE;
			UIHelper.addBitmapDataChild(this, mainbackground);
			btn_GameWord=UIHelper.addBitmapDataButtonChild(this, main_gameword_up, main_gameword_down, onGameWorldClickHandler, 0, 67);
			UIHelper.addRectSpriteChild(this, mainMenuMask, "mainMenuMask", this.mainMenuStartX, this.mainMenuStartY, this.mainMenuWidth, this.mainMenuHeight);
			UIHelper.addRectSpriteChild(this, mainMenuContainer, "mainMenuContainer", mainMenuStartX, mainMenuStartY);
			this.mainMenuContainer.mask=this.mainMenuMask;
			initMainMenu();
			//默认是合起的
			this.mainMenuContainer.y=this.mainMenuStartY - this.mainMenuContainer.height;
			myTween=new Tween(this.mainMenuContainer, "y", Strong.easeOut, this.mainMenuContainer.y, 100, 3, true);
			myTween.stop();
//			desktable=new DeskTable();
//			UIHelper.addSpriteChild(this,desktable,"DeskTable",146,67);
		}

		private function initMainMenu():void
		{
			UIHelper.addBitmapDataButtonChild(this.mainMenuContainer, main_live_dealer, main_live_dealer, onGameLiveDealerClickHandler, 0, this.mainMenuContainer.height, true);
			UIHelper.addBitmapDataButtonChild(this.mainMenuContainer, main_menu_d_up, main_menu_d_up, onGameMenuUpClickHandler, 0, this.mainMenuContainer.height, true);
			for (var i:int=0; i < 5; i++)
			{
				mainMenuArray.push(new MainMenuItem("maintextmenu" + i, mainmenu_out, mainmenu_up, new DeskTable()));
			}
			for (var j:int=0; j < mainMenuArray.length; j++)
			{
				UIHelper.addSpriteChild(this.mainMenuContainer, mainMenuArray[j], "mainMenuArray" + j, 0, this.mainMenuContainer.height + 5);
			}
			UIHelper.addBitmapDataChild(this.mainMenuContainer, main_game_search, 0, this.mainMenuContainer.height);
		}

		private function onGameMenuUpClickHandler(e:MouseEvent):void
		{
			// TODO Auto Generated method stub

		}

		private function onGameLiveDealerClickHandler(e:MouseEvent):void
		{
			// TODO Auto Generated method stub

		}

		private function onGameWorldClickHandler(e:MouseEvent):void
		{
			// TODO Auto Generated method stub
			//Debuger.print("onGameWorldClickHandler:"+e.currentTarget);
			if (boolTweenLite)
			{
				if (!boolShowMenu)
				{
					TweenLite.to(mainMenuContainer, 1, {y: this.mainMenuStartY});
				}
				else
				{
					TweenLite.to(mainMenuContainer, 1, {y: this.mainMenuStartY - mainMenuContainer.height});
				}
			}
			else
			{
				//Tween.addTween(this,{Acceleration:70,time:0.4, transition:"easeInSine",onComplete:SoundPlay});//70是控制旋转速度	
				if (!boolShowMenu)
				{
					myTween.begin=this.mainMenuContainer.y;
					myTween.finish=100;
					trace("展开,begin" + myTween.begin + " end:" + myTween.finish);
					myTween.start();
						//myTween.yoyo();
				}
				else
				{
//					myTween.rewind();
//					myTween.start();
					myTween.yoyo();
					trace("合起,begin" + myTween.begin + " end:" + myTween.finish);
				}

			}

			boolShowMenu=!boolShowMenu;

		}

	}
}
